ccR.Paladin = {
}
setmetatable(ccR.Paladin,ccR)

ccR.Paladin.Feature = {
	Cleanse = 
	function(unit)
		if unit == nil then unit = "player" end
		if unit ~= "player" and (not ccR.Unit.Exists(unit) or not ccR.Unit.Is.Alive(unit)) then return end
		for x = 1, # tblCleanseBlacklist do
			local vAura = tblCleanseBlacklist[x]
			if ccR.Unit.Has.Debuff(unit, vAura) or ccR.Unit.Has.Buff(unit, vAura) then return end
		end
		if ccR.Spell.Is.Ready(CLEANSE) then
			-- Blacklist check
			for i = 1, 40 do 
			 	local name, _, _, _, debuffType = UnitDebuff(unit, i) 
			 	if name == nil then	
			 		break 
			 	else 
			 		if ccR.Player.Specialization() == 1 then
				 		if debuffType == "Poison"
				 		or debuffType == "Disease"
				 		or debuffType == "Magic"
				 		then
				 			ccR.Cast.Spell(CLEANSE, unit)	
				 			return
				 		end
			 		else
				 		if debuffType == "Poison"
				 		or debuffType == "Disease"
				 		then
				 			ccR.Cast.Spell(CLEANSE, unit)	
				 			return
				 		end
				 	end
			 	end
			end
		end
	end,
	Avenging_Wrath = function() if ccR.Spell.Is.Ready(AVENGING_WRATH) then ccR.Cast.Spell(AVENGING_WRATH) end end,
	Avenging_Wrath_on_Boss_and_Buff = function() if ccR.Spell.Is.Ready(AVENGING_WRATH) and ccR.Target.Is.Boss() and (ccR.Player.Has.Buff(BLOODLUST)	or ccR.Player.Has.Buff(HEROISM)	or ccR.Player.Has.Buff(TIME_WARP) or ccR.Player.Has.Buff(ANCIENT_HYSTERIA) or ccR.Player.Has.Buff(NETHERWINDS)	or ccR.Player.Has.Debuff(ANCIENT_HYSTERIA) or ccR.Player.Has.Debuff(NETHERWINDS) or ccR.Player.Has.Debuff(SATED)	or ccR.Player.Has.Debuff(EXHAUSION)) then ccR.Cast.Spell(AVENGING_WRATH) end end,
	Rebuke = function(time)	
		if time == nil then time = 1 end
		if ccR.Spell.Is.Ready(REBUKE) then
			for x = 1, # ccR_Enemies_Within_8 do
				local vUnit = ccR_Enemies_Within_8[x]
				if ccR.Unit.Exists(vUnit)
				and ccR.Unit.Is.CastingOrChanneling(vUnit) 
				and ccR.Unit.Is.Interuptable(vUnit) 
				and (ccR.Player.Is.Facing(vUnit) or ccR.Var("fh_Always_Facing"))
				and ccR.Spell.CanAttack(REBUKE, vUnit)
				then 
					if ccR.Unit.Has.LeftOnCast(vUnit, time) then ccR.Cast.Attack(REBUKE, vUnit) end 
					if ccR.Unit.Is.Channeling(vUnit) then ccR.Cast.Attack(REBUKE, vUnit) end 
				end
			end
		end
	end,
	Hammer_of_Wrath = 
	function()
		if ccR.Spell.CanAttack(HAMMER_OF_WRATH) and	((not ccR.Player.Has.Spell(EMPOWERED_HAMMER_OF_WRATH) and ccR.Target.Health() <= 20) or (ccR.Player.Has.Spell(EMPOWERED_HAMMER_OF_WRATH) and ccR.Target.Health() <= 35)	or ccR.Player.Has.Buff(AVENGING_WRATH))	then ccR.Cast.Attack(HAMMER_OF_WRATH) end
		for x = 1, # ccR_Enemies_In_Combat do
			local vUnit = ccR_Enemies_In_Combat[x]
			if ccR.Unit.Is.Alive(vUnit)
			and (ccR.Player.Is.Facing(vUnit) or ccR.Var("fh_Always_Facing"))
			and (
				(not ccR.Player.Has.Spell(EMPOWERED_HAMMER_OF_WRATH) and ccR.Unit.Health(vUnit) <= 20)
				or
				(ccR.Player.Has.Spell(EMPOWERED_HAMMER_OF_WRATH) and ccR.Unit.Health(vUnit) <= 35) 
				or
				ccR.Player.Has.Buff(AVENGING_WRATH)
				)
			and ccR.Spell.CanAttack(HAMMER_OF_WRATH, vUnit)
			and ccR.Spell.CooldownTime(HAMMER_OF_WRATH) == 0
			then
				ccR.Cast.Attack(HAMMER_OF_WRATH, vUnit)
			end
		end
	end,
	Hammer_of_Justice =	function() if ccR.Target.Exists() and (ccR.Player.Is.Facing("target") or ccR.Var("fh_Always_Facing")) then if ccR.Spell.CanAttack(HAMMER_OF_JUSTICE) and not ccR.Target.Is.Boss() then ccR.Cast.Attack(HAMMER_OF_JUSTICE) end if ccR.Spell.CanAttack(FIST_OF_JUSTICE) and not ccR.Target.Is.Boss() then ccR.Cast.Attack(FIST_OF_JUSTICE) end end end,
	Hand_of_Freedom = function() if ccR.Spell.Is.Ready(HAND_OF_FREEDOM) and not ccR.Player.Has.Buff(HAND_OF_FREEDOM) then local eventIndex = C_LossOfControl.GetNumEvents() while (eventIndex > 0) do local _, _, text = C_LossOfControl.GetEventInfo(eventIndex) if text == LOSS_OF_CONTROL_DISPLAY_ROOT or text == LOSS_OF_CONTROL_DISPLAY_SNARE then ccR.Cast.Spell(HAND_OF_FREEDOM, "player")	return end	eventIndex = eventIndex - 1	end	end	end,
	Divine_Protection = function(health) if health == nil then health = 60 end if ccR.Spell.Is.Ready(DIVINE_PROTECTION) and ccR.Player.Health() <= health then ccR.Cast.Spell(DIVINE_PROTECTION) end end,
	Divine_Shield = function(health) if health == nil then health = 35 end if ccR.Spell.Is.Ready(DIVINE_SHIELD) and not ccR.Player.Has.Debuff(FORBEARANCE) and ccR.Player.Health() <= health then ccR.Cast.Spell(DIVINE_SHIELD, "player") end end,
	Lay_on_Hands = function(health)	if health == nil then health = 10 end if ccR.Spell.Is.Ready(LAY_ON_HANDS) and not ccR.Player.Has.Debuff(FORBEARANCE) and ccR.Player.Health() <= health then ccR.Cast.Spell(LAY_ON_HANDS, "player") end end,
	Hand_of_Protection = function(health) if health == nil then health = 10 end if ccR.Spell.Is.Ready(HAND_OF_PROTECTION) and not ccR.Player.Has.Debuff(FORBEARANCE) and ccR.Player.Health() <= 5 then ccR.Cast.Spell(HAND_OF_PROTECTION, "player") end end,
	Word_of_Glory =
	function(health, hp)
		if health == nil then health = 75 end
		hp = hp or 3
		if ccR.Spell.Is.Ready(WORD_OF_GLORY)
		and ccR.Player.Health() <= health
		and (ccR.Player.Holy_Power() >= hp or ccR.Player.Has.Buff(DIVINE_PURPOSE)) 
		then
			ccR.Cast.Spell(WORD_OF_GLORY, "player")
		end
	end,
}
setmetatable(ccR.Paladin.Feature,ccR)